{% extends "common/layout.html" %}



{% block content %}
    <div class="row">
        <div class="col-sm-12">
            <div class="row">
                <div class="col-sm-10 ">
                    <h2>招定标档案信息台账</h2>
                </div>
            </div>
        </div>
    </div>


    <div class="row" style="margin-top: 30px">
        <div class="col-sm-12">

            {#搜索#}
            <div class="row search">

                <div class="col-sm-1 ">
                    <label>公司</label>
                    <select class="form-control " name="company">
                        {% if current_user.company == '西北区域公司' %}
                            <option>不限</option>
                            <option>山西公司</option>
                            <option>太原公司</option>
                            <option>大同公司</option>
                            <option>临汾公司</option>
                            <option>长治公司</option>
                            <option>内蒙古公司</option>
                            <option>呼和浩特公司</option>
                            <option>包头公司</option>
                            <option>通辽公司</option>
                            <option>乌兰察布公司</option>
                            <option>陕西公司</option>
                            <option>西安公司</option>
                            <option>宝鸡公司</option>
                            <option>渭南公司</option>
                            <option>乌鲁木齐公司</option>
                            <option>兰州公司</option>
                        {% endif %}
                        {% for item in current_user.company | tolist %}
                            <option>{{ item }}</option>
                        {% endfor %}
                    </select>
                </div>


                <div class="col-sm-1 ">
                    <label>招标形式</label>
                    <select class="form-control " name="form">
                        {% if form %}
                            <option>{{ form }}</option>
                        {% endif %}
                        <option>不限</option>
                        <option>招标</option>
                        <option>其他</option>
                    </select>
                </div>

                <div class="col-sm-1 ">
                    <label>工程类别</label>
                    <select class="form-control " name="type">
                        {% if type %}
                            <option>{{ type }}</option>
                        {% endif %}
                        <option>不限</option>
                        {% for item in bookclass %}
                            <option>{{ item.name }}</option>
                        {% endfor %}
                    </select>
                </div>


                <div class="col-sm-1 ">
                    <label>是否过百万</label>
                    <select class="form-control " name="isover">
                        {% if current_user.company =="西北区域公司" %}
                            <option>不限</option>
                            <option>是</option>
                        {% endif %}
                        <option>否</option>
                    </select>
                </div>

                <div class="col-sm-2 ">
                    <label>工程名称</label>
                    <input class="form-control " name="gcname">
                </div>

{#                <div class="col-sm-2 ">#}
{#                    <label>档案编号</label>#}
{#                    <input class="form-control " name="sn">#}
{#                </div>#}


                <div class='col-sm-1'>
                    <div class="form-group">
                        <label></label>
                        <button type="submit" class="btn btn-primary btn-block do-search " id="dosearch">
                            搜索
                        </button>
                    </div>
                    <script type="text/javascript">
                        {#搜索#}
                        var dosearch = {
                            init: function () {
                                this.eventBind()
                            },
                            eventBind: function () {
                                $(".do-search").click(function () {
                                    {#var sn = $(".search input[name=sn]").val();#}
                                    var type = $(".search select[name=type]").val();
                                    var form = $(".search select[name=form]").val();
                                    var company = $(".search select[name=company]").val();
                                    var isover = $(".search select[name=isover]").val();
                                    var gcname = $(".search input[name=gcname]").val();
                                    var urlindex = common_ops.buildUrl("/book/booksearch?type=") + type + "&form=" + form + "&company=" + company + "&isover=" + isover + "&gcname=" + gcname + "&mark=1";
                                    document.location.href = urlindex;

                                });
                            }
                        };
                        $(document).ready(function () {
                            dosearch.init();
                        });
                    </script>
                </div>

                {#                <div class='col-sm-1'>#}
                {#                    <label></label>#}
                {#                    <div class="form-group">#}
                {#                        <button type="submit" class="btn btn-success btn-sm btn-block do-export " id="doexport">#}
                {#                            导出#}
                {#                        </button>#}
                {#                    </div>#}
                {##}
                {#                    <script type="text/javascript">#}
                {#                        var exporter = {#}
                {#                            init: function () {#}
                {#                                this.eventBind()#}
                {#                            },#}
                {#                            eventBind: function () {#}
                {#                                $(".do-export").click(function () {#}
                {#                                    var starttime = $(".time-pick input[name=starttime]").val();#}
                {#                                    var endtime = $(".time-pick input[name=endtime]").val();#}
                {#                                    var urlindex = common_ops.buildUrl("/seal/export?starttime=") + starttime + "&endtime=" + endtime;#}
                {#                                    document.location.href = urlindex;#}
                {##}
                {#                                });#}
                {#                            }#}
                {#                        };#}
                {#                        $(document).ready(function () {#}
                {#                            exporter.init();#}
                {#                        });#}
                {#                    </script>#}
                {#                </div>#}
            </div>

            {#        新建#}
            <div class="row">
                <button type="button" class="btn btn-info" data-toggle="modal"
                        data-target="#exampleModal" style="margin-top: 10px;margin-left: 15px" data-form=""
                        data-company="" data-type=""
                        data-sn="" data-bname="" data-gcname=""
                        data-num="" data-projectname="" data-dbtime="" data-zjzb=""
                        data-special="" data-title="新建"><span
                        class="glyphicon glyphicon-plus" aria-hidden="true"></span>新建存档
                </button>
            </div>

            {#表格#}
            <row class=" data-table">
                <table class="table table-bordered table-hover">
                    <tr>
                        <th class="info">编号</th>
                        <th class="info">项目类别</th>
                        <th class="info">工程名称</th>
                        <th class="info">中标单位</th>
                        <th class="info">中标金额(元)</th>
                        <th class="info">造价指标</th>
                        <th class="info">定标时间</th>
                        <th class="info">特殊情况概述</th>
                        <th class="info">所属公司</th>
                        <th class="info">操作</th>
                    </tr>
                    {% for item in bookindex %}

                        <tr>
                            <th>{{ item.sn }}</th>
                            <th>{{ item.type }}</th>
                            <th>{{ item.gcname }}</th>
                            <th>{{ item.bname }}</th>
                            <th>{{ item.num }}</th>
                            <th>{{ item.zjzb }}</th>
                            <th>{{ item.dbtime }}</th>
                            <th>{{ item.special }}</th>
                            <th>{{ item.company }}</th>
                            <th><a class="btn btn-success"
                                   href="{{ buildUrl('/book/bookdetail') }}?id={{ item.id }}">查看</a>

                                {#                                {% if item.company ==  current_user.company or current_user.company== "西北区域公司" %}#}

                                <button type="button" class="btn btn-primary" data-toggle="modal"
                                        data-target="#exampleModal" data-form="{{ item.form }}"
                                        data-company="{{ item.company }}" data-type="{{ item.type }}"
                                        data-sn="{{ item.sn }}" data-bname="{{ item.bname }}"
                                        data-num="{{ item.num }}" data-projectname="{{ item.projectname }}"
                                        data-pid="{{ item.id }}" data-gcname="{{ item.gcname }}"
                                        data-dbtime="{{ item.dbtime }}" data-zjzb="{{ item.zjzb }}"
                                        data-special="{{ item.special }}"
                                        data-title="编辑">编辑
                                </button>

                                <button type="button" class="btn btn-danger" data-toggle="modal"
                                        data-target="#conModal" data-id="{{ item.id }}">删除
                                </button>

                                {#                                {% endif %}#}

                            </th>
                        </tr>

                    {% endfor %}
                </table>
            </row>

            {#        分页#}
            {% if pages %}
                <div>
                    {% include "common/pagenation.html" %}
                </div>
            {% endif %}
        </div>
    </div>


    {#    确认模态框#}
    <div class="modal fade" id="conModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">操作确认</h4>
                </div>
                <div class="modal-body">
                    <p>是否确定删除?</p>
                    <input type="text" style="display:none" id="deleteid" name="deleteid">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button class="btn btn-danger do-delete" type="submit" name="delete" id="delete" >确定删除</button>
                </div>
            </div>
        </div>
    </div>


    {#    模态框#}
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">新建存档</h4>
                </div>
                <div class="modal-body">

                    {#                    <form class="form" style="margin-top: 10px" method="post" id="postform"#}
                    {#                          action="{{ buildUrl('/book/addindex') }}" name="postform">#}
                    {#                    <form style="margin-top: 10px">#}


                    <input type="text" class="invisible" id="uid" name="uid" value="{{ current_user.id }}">
                    <input type="text" class="invisible" id="pid" name="pid">

                    <input type="text" class="invisible" id="usercompany" name="usercompany"
                           value="{{ current_user.company }}">


                    <div class="form-group">
                        <label for="recipient-name" class="control-label">档案编号:</label>
                        <input type="text" class="form-control" id="sn" name="sn">
                    </div>


                    <div class="form-group">
                        <label for="recipient-name" class="control-label">项目类型:</label>
                        <select class="form-control " id="type" name="type">
                            {% for item in bookclass %}
                                <option>{{ item.name }}</option>
                            {% endfor %}
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">项目名称:</label>
                        <input type="text" class="form-control" id="projectname" name="projectname">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">工程名称:</label>
                        <input type="text" class="form-control" id="gcname" name="gcname">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">中标单位:</label>
                        <input type="text" class="form-control" id="bname" name="bname">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">中标金额（元）:</label>
                        <input type="text" class="form-control" id="num" name="num">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">造价指标:</label>
                        <input type="text" class="form-control" id="zjzb" name="zjzb">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">定标时间:</label>
                        <a class='input-group date' id='datetimepicker1'>
                            <input type='text' class="form-control" id="dbtime" name="dbtime"/>
                            <span class="input-group-addon">
		                    <span class="glyphicon glyphicon-calendar"></span>
		                </span>
                        </a>
                    </div>

                    <script type="text/javascript">

                        $('#datetimepicker1').datetimepicker({
                            format: 'YYYY-MM-DD',
                            locale: moment.locale('zh-cn')
                        });


                    </script>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">特殊情况概述:</label>
                        <input type="text" class="form-control" id="special" name="special">
                    </div>


                    <div class="form-group">
                        <label for="recipient-name" class="control-label">所属公司:</label>
                        <select id="company" name="company" class="form-control">

                            {#                            <option>{{ current_user.company | tolist }}</option>#}
                            {% for item in current_user.company | tolist %}
                                <option>{{ item }}</option>
                            {% endfor %}

                            {% if current_user.company == '西北区域公司' %}
                                <option>山西公司</option>
                                <option>太原公司</option>
                                <option>大同公司</option>
                                <option>临汾公司</option>
                                <option>长治公司</option>
                                <option>内蒙古公司</option>
                                <option>呼和浩特公司</option>
                                <option>包头公司</option>
                                <option>通辽公司</option>
                                <option>乌兰察布公司</option>
                                <option>陕西公司</option>
                                <option>西安公司</option>
                                <option>宝鸡公司</option>
                                <option>渭南公司</option>
                                <option>乌鲁木齐公司</option>
                                <option>兰州公司</option>
                            {% endif %}
                        </select>
                    </div>


                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button class="btn btn-primary do-add" type="submit" name="add" id="add">新建存档</button>
                        <button class="btn btn-primary do-updata" type="submit" name="updata" id="updata">更新存档</button>
                    </div>
                </div>

            </div>
        </div>
    </div>

    {#    更新文档#}
    <script>
        $(".do-updata").click(function () {
            var btnaction = $(this);
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var projectname = $("input[id=projectname]").val();
            var sn = $("input[id=sn]").val();
            var bname = $("input[id=bname]").val();
            var num = $("input[id=num]").val();
            var type = $("select[id=type]").val();
            var company = $("select[id=company]").val();
            var uid = $("input[id=uid]").val();
            var id = $("input[id=pid]").val();
            var gcname = $("input[id=gcname]").val();
            var dbtime = $("input[id=dbtime]").val();
            var zjzb = $("input[id=zjzb]").val();
            var special = $("input[id=special]").val();


            $.ajax({
                url: common_ops.buildUrl("/book/updataindex"),
                type: "POST",
                data: {
                    projectname: projectname,
                    sn: sn,
                    bname: bname,
                    num: num,
                    type: type,
                    company: company,
                    uid: uid,
                    id: id,
                    gcname: gcname,
                    dbtime: dbtime,
                    zjzb: zjzb,
                    special: special,
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#exampleModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = common_ops.buildUrl("/book/bookindex");
                        $("#exampleModal").trigger("click");
                    }, 1000)
                }
            });

        });
    </script>


    <script>
        $(".do-add").click(function () {
            var btnaction = $(this);
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var projectname = $("input[id=projectname]").val();
            var sn = $("input[id=sn]").val();
            var bname = $("input[id=bname]").val();
            var num = $("input[id=num]").val();
            var type = $("select[id=type]").val();
            var company = $("select[id=company]").val();
            var uid = $("input[id=uid]").val();
            var gcname = $("input[id=gcname]").val();
            var dbtime = $("input[id=dbtime]").val();
            var zjzb = $("input[id=zjzb]").val();
            var special = $("input[id=special]").val();


            $.ajax({
                url: common_ops.buildUrl("/book/addindex"),
                type: "POST",
                data: {
                    projectname: projectname,
                    sn: sn,
                    bname: bname,
                    num: num,
                    type: type,
                    company: company,
                    uid: uid,
                    gcname: gcname,
                    dbtime: dbtime,
                    zjzb: zjzb,
                    special: special,
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#exampleModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = common_ops.buildUrl("/book/bookindex");
                        $("#exampleModal").trigger("click");
                    }, 1000)

                }
            });

        });
    </script>

    {#删除数据#}
    <script>
        $(".do-delete").click(function () {
            var btnaction = $(this);
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var deleteid = $("input[id=deleteid]").val();
            console.log(deleteid);


            $.ajax({
                url: common_ops.buildUrl("/book/deleteindex"),
                type: "GET",
                data: {
                    id: deleteid,
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#conModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = common_ops.buildUrl("/book/bookindex");
                        $("#exampleModal").trigger("click");
                    }, 1000)

                }
            });

        });
    </script>


    <script>
        {#编辑赋值#}
        $('#exampleModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget); // Button that triggered the modal
            var projectname = button.data('projectname');
            var sn = button.data('sn');
            var bname = button.data('bname');
            var num = button.data('num');
            var type = button.data('type');
            var title = button.data('title');
            var id = button.data('pid');
            var gcname = button.data('gcname');
            var dbtime = button.data('dbtime');
            var zjzb = button.data('zjzb');
            var special = button.data('special');

            var modal = $(this)
            modal.find('.modal-title').text(title + '存档');
            document.getElementById("projectname").value = projectname;
            document.getElementById("sn").value = sn;
            document.getElementById("bname").value = bname;
            document.getElementById("num").value = num;
            document.getElementById("type").value = type;
            document.getElementById("pid").value = id;
            document.getElementById("gcname").value = gcname;
            document.getElementById("dbtime").value = dbtime;
            document.getElementById("zjzb").value = zjzb;
            document.getElementById("special").value = special;


            if (title == '编辑') {
                document.getElementById("add").style.display = "none";
                document.getElementById("updata").style.display = "";

            } else {
                document.getElementById("updata").style.display = "none";
                document.getElementById("add").style.display = "";
            }

        });


        {#删除赋值#}
        $('#conModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var deleteid = button.data('id');
            document.getElementById("deleteid").value = deleteid;
        });
    </script>



{% endblock %}





{#{% block css %}#}
{#    <link rel="stylesheet" href="{{ buildStaticUrl('/plugins/bootstrap-select/bootstrap-select.css') }}">#}
{#{% endblock %}#}